package com.gzx.plugin.data.wxjk.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.gzx.plugin.data.core.consts.CompanyConstants;
import com.gzx.plugin.data.wxjk.entity.DataWxjkContactInfo;
import com.gzx.plugin.data.wxjk.mapper.DataWxjkContactInfoMapper;
import com.gzx.plugin.data.wxjk.service.IDataWxjkContactInfoService;
import com.gzx.tjzy.feign.req.liaison.GzxDebtorLiaisonReqDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import vip.xiaonuo.common.util.CommonCryptogramUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
@DS("data")
@RequiredArgsConstructor
public class DataWxjkContactInfoServiceImpl implements IDataWxjkContactInfoService {

    private final DataWxjkContactInfoMapper dataWxjkContactInfoMapper;
    @Override
    public List<GzxDebtorLiaisonReqDto> queryByBussnissId(Map<Long, String> map) {
        List<GzxDebtorLiaisonReqDto> resultList = new ArrayList<>();
        List<DataWxjkContactInfo> contactInfoList = dataWxjkContactInfoMapper.getDataByBusinessIds(map.keySet());
        if (!CollectionUtils.isEmpty(contactInfoList)) {
            for (DataWxjkContactInfo contactInfo : contactInfoList) {
                GzxDebtorLiaisonReqDto gzxDebtorRelationPhone = new GzxDebtorLiaisonReqDto();
                gzxDebtorRelationPhone.setProjectCode(CompanyConstants.WXJK_PROJECT_CODE);
                gzxDebtorRelationPhone.setRelationship(contactInfo.getContactShip());
                gzxDebtorRelationPhone.setLiaisonName(contactInfo.getContactName());
                gzxDebtorRelationPhone.setLiaisonPhone(CommonCryptogramUtil.doSm1AesEncrypt(contactInfo.getContactTel()));
                gzxDebtorRelationPhone.setPhoneSource(5);
                gzxDebtorRelationPhone.setPhoneStatus(1);
                gzxDebtorRelationPhone.setDebtorCardId(CommonCryptogramUtil.doSm1AesEncrypt(map.get(contactInfo.getBusinessId())));
                resultList.add(gzxDebtorRelationPhone);
            }
        }
        return resultList;
    }
}
